<?php
namespace App\Models;
use Illuminate\Http\Request;
use DB;



/**
 * 管理员模型类
 */
class Project_admin_role extends BaseModel
{

    public $table = "project_admin_role";    //指定表名

    /**
     * 检测角色是否存在
     * @param $request
     * @return mixed
     */
    public function existRoleName($request)
    {
        $roleName = project_admin_role::where('username',$request->username)->count();
        if($roleName  != 0){
            return true;
        } else {
            return false;
        }
    }

    /**
     * 执行保存或添加角色动作
     * @param $request
     * @param int $first
     * @return bool
     */
    public function createOrSave($request, $first=0)
    {
        $this->username = $request ->username;
        $this->status = isset($request->status)?$request->status:"0";
        if($first == 0){
            $this ->addtime =$this->lasttime = date("Y-m-d H:i:s",time());
        } elseif ($first == 1){
            $this->lasttime = date("Y-m-d H:i:s",time());
        }
        return $this->save();
    }

}